// matmulttest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

int getLinearIndex(int cols, int rowidx, int colidx)
{
	return rowidx * cols + colidx;
}

template <class T>
void matmultcpu(const T* A, const T* B, int yA, int xA, int xB, T* C)
{
	for (int ro = 0; ro < yA; ++ro)
	{
		for (int co = 0; co < xB; ++co)
		{
			T sum = 0;
			for (int mm = 0; mm < xA; ++mm)
			{
				int indexA = getLinearIndex(xA, ro, mm);
				int indexB = getLinearIndex(xB, mm, co);
				sum += A[indexA] * B[indexB];
			}
			int indexC = getLinearIndex(xB, ro, co);
			C[indexC] = sum;
		}
	}
}

int _tmain(int argc, _TCHAR* argv[])
{
	float A[] = { 1, 1, 1, 1 };
	float B[] = { 1, 1, 1, 1 };
	float C[] = { 0, 0, 0, 0 };

	matmultcpu<float>(A, B, 2, 2, 2, C);

	return 0;
}

